import datetime
import random
from function_tool import time_format_transform

import clickhouse_connect

connect_info = {
    'port': 8123,
    'host': '192.168.104.243',
    'username': 'default',
    'password': 'bwda2025',
    'database': 'lap'
}

client = clickhouse_connect.get_client(**connect_info)
sql00 = """
        select zy_resource_code, zy_resource_name, zy_sys_person_responsible_name, zy_sys_person_responsible 
        from dim_id_basic_data_res
        """
result_ck = client.query(sql00)
result = result_ck.result_rows
column_list = ['bwd_create_time', 'id', 'op_time', 'zy_resource_name', 'zy_resource_code',
               'zy_master_account_name', 'zy_master_account_id']
insert_data = []
table = 'ads_app_code_local'
for i in range(100):
    bwd_create_time = time_format_transform.TimeFormatTransform().get_random_date('2025-08-20', '2025-08-23')
    op_time = bwd_create_time
    zy_id = str(random.randint(10 ** 14, 10 ** 16))
    zy_resource_name = random.choice(result)[1]
    zy_resource_code = random.choice(result)[0]
    zy_master_account_name = random.choice(result)[2]
    zy_master_account_id = random.choice(result)[-1]
    insert_data.append([bwd_create_time, zy_id, op_time, zy_resource_name, zy_resource_code,
                       zy_master_account_name, zy_master_account_id])
client.insert(table, insert_data, column_names=column_list)
client.close()
